;;;; Rogue Skirmish copyright 2010 Adam White (theroguemonkey@gmail.com)
;;;; Licensed under GNU General Public Licence v2 or later - refer COPYING

(cl:defpackage :skirmish
  (:use #:common-lisp #:rllib)
  (:shadow #:describe))

(in-package :skirmish)

(defparameter *map* nil
  "Game map")

(defparameter *panels* nil
  "List of PANELs to be shown")

(defparameter *callbacks* nil
  "Association list of functions to be called on input. 
Functions should return :end to signal no further processing of list required.")

(defparameter *idle* nil
  "List of functions to be called on the idle loop. 
Functions should return :end to signal no further processing of list required")

(defparameter *default-cursor* nil
  "Normal cursor to display")

(defparameter *play* nil
  "PANEL for the play area")

(defparameter *info* nil
  "PANEL for the info area")

(defun render-game ()
  (apply #'render-all *panels* (sdl-get-mouse-position)))

(defun act-next ()
  (bwhen actor (next-actor *map*)
	 (act actor)))


(defun skirmish (&key (width 1280) (height 960) &aux (info-x (floor width 4/3)) 
		 (tm (get-internal-real-time)) (c 0))
  (with-opengl-init (width height "Roguelike Skirmish")    
    (setf *base-dir* (get-base-dir "Resources/")
	  *idle* nil
	  *callbacks* nil
	  *map* (create-cave-map 32 32 nil :rock-wall 2 3 60)
	  *play* (make-map-panel *map* 0 0 info-x height)
	  *info* (make-panel info-x 0 (- width info-x) height)
	  *panels* (list *play* *info*)
	  tm (get-internal-real-time))
    (read-rc-file "terrainrc")
    (sdl-hide-cursor)
    (rllib::push-mouse nil (make-output-texture :normal-pointer 0 0))
    (push-idle *idle* :paint #'render-game)   
    (push-idle *idle* :act #'act-next)
    (with-events () 
      (:key-down (:sym sym :mod mods) (callbacks *callbacks* :key-down :sym sym :mod mods))
      (:button-down (:button button) (callbacks *callbacks* :button-down :button button))
      (:quit () t)
      (:idle () (idle *idle*) (incf c))))
  (float   (/ c (/ (- (get-internal-real-time) tm) internal-time-units-per-second))))
  